package Service;

import java.util.ArrayList;
import java.util.List;

import Dao.BanDao;
import Dao.CjDao;
import Dao.CourseDao;
import Dao.UserDao;
import vo.Ban;
import vo.Cjb;
import vo.Kc;
import vo.User;

public class Servlet {
	private UserDao xs = new UserDao();
	private BanDao bj = new BanDao();
	private CourseDao kc = new CourseDao();
	private CjDao cj = new CjDao();

	public User longin(String username, String password) {
		User s = xs.longin(username,password);
		return s;
	}

	public void add(Ban re) {
		bj.add(re);
	}

	public List<Ban> find() {
		List<Ban> list = bj.find();
		return list;
	}

	public List<User> find1() {
		List<User> list = xs.find1(); 
		return list;
	}

	public User findById(Integer id) {
		User us = xs.findById(id);
		return us;
	}

	public void modifyPwd(User us) {
		xs.modifyPwd(us);
		
	}

	public List<Kc> findKc() {
		List<Kc> list = kc.findKc();
		return list;
	}

	public void addkc(Kc re) {
		kc.addkc(re);
		
	}

	public void addxs(User re) {
		xs.addxs(re);
		
	}

	public void deletebj(Integer id) {
		bj.deletebj(id);		
	}

	public void deletexs(Integer id) {
		xs.deletexs(id);
		
	}

	public void deletekc(Integer id) {
		kc.deletekc(id);
		
	}

	public User findxs(Integer id) {
		User a = xs.findById(id);
		return a;
	}

	public void studentxg(User str) {
		xs.studentxg(str);
		
	}

	public Ban findbj(Integer id) {
		Ban a = bj.FindById(id);
		return a;
	}

	public void banjixg(Ban str) {
		bj.banjixg(str);
	}

	public Kc findkc(Integer id) {
		Kc a = kc.findkc(id);
		return a;
	}

	public void coursexg(Kc str) {
		kc.coursexg(str);
		
	}

	public List<User> findBybjid(Integer cless_id) {
		List<User> list = xs.findBybjid(cless_id);
		return list;
	}
	
	public List<User> findBybjid1(Integer cless_id, Integer kc_id) {
		List<User> list = xs.findBybjid1(cless_id, kc_id);
		return list;
	}

	public void cjgl(Cjb str) {
		cj.cjgl(str);
	}

	public List<Cjb> find2() {
		return cj.find2();
	}

	public void update(Cjb str) {
		cj.update(str);
	}

	public List<Cjb> findBybjid2(Integer user_id) {
		List<Cjb> list = cj.findBybjid2(user_id);
		return list;
	}

	public List<Cjb> findByXsid(Integer user_id) {
		List<Cjb> list = cj.findByXsid(user_id);
		return list;
	}

	public Kc findall() {
		Kc a = kc.findall();
		return a;
	}

	public List<Kc> findAllcj(Integer cless_id) {
		return cj.findAllcj(cless_id);
	}

	public List<List<Object>> Deng(List<Kc> kc2, List<User> xs2) {
		List<List<Object>> list = new ArrayList<>();
		for(User s: xs2){
			List<Object> list2 = new ArrayList<>();
			list2.add(s.getUsername());
			list2.add(s.getName());
			for(Kc c:kc2){
				list2.add(cj.findByXsKcId(s.getId(),c.getId()));
			}
			list.add(list2);
		}
		return list;
	}

	public void cjxg(Integer id, Integer achievement) {
		Cjb cjb = cj.findBycjid(id);
		cjb.setAchievement(achievement);
		cj.updateByid(cjb);
	}


}
